/*
 * Copyright (c) 2023 fred
 * Licensed under the Apache License,Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
import { CharacterReader } from './CharacterReader';

export class ParseError {
  private _pos: number;
  private _errorMsg: string;
  private _cursorPos: string

  constructor(reader: CharacterReader, errorMsg: string);

  constructor(pos: number, errorMsg: string);

  constructor(arg1: any, arg2: string) {
    if (arg1 instanceof CharacterReader) {
      this._pos = arg1.pos()
      this._cursorPos = arg1.cursorPos()
      this._errorMsg = arg2
    } else if (typeof arg1 === 'number') {
      this._pos = arg1
      this._cursorPos = `${arg1}`
      this._errorMsg = arg2
    }
  }

  /**
   * Retrieve the error message.
   * @return the error message.
   */
  public getErrorMessage(): string {
    return this._errorMsg;
  }

  /**
   * Retrieves the offset of the error.
   * @return error offset within input
   */
  public getPosition(): number {
    return this._pos;
  }

  /**
   Get the formatted line:column cursor position where the error occurred.
   @return line:number cursor position
   */
  public getCursorPos(): string {
    return this._cursorPos
  }

  public toString(): string {
    return `<${this._cursorPos}>:${this._errorMsg}`
  }
}

